package com.ingrid.web.compras.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.ingrid.web.compras.model.DAO;
import com.ingrid.web.compras.model.Product;

public class AddToBasketServlet extends HttpServlet {

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		HttpSession session = req.getSession();
		String sessionId = session.getId();

		String productId = req.getParameter("productId").toString();

		DAO dao = DAO.getInstance();
		Product product = dao.findProduct(Integer.parseInt(productId));
		dao.addToBasket(sessionId, product);

		resp.sendRedirect("/carrinhoDeCompras.jsp");
	}
}
